package com.leyou.common.advice;

import com.leyou.common.exception.LyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice  //表示所有的被扫描到的controller都有效，表示controller中所有的方法，相当于给所有的方法写了try
public class ControllerExceptionHandler {

    //相当于曾经的catch
    @ExceptionHandler(LyException.class)
    public ResponseEntity<String> handlerException(LyException ex){
        return ResponseEntity.status(ex.getStatus()).body(ex.getMessage());
    }


}
